﻿#region Usings

using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using SilverBox.Helpers;

#endregion

namespace SilverBox.Extensions
{
    public static class ControlTreeHelperExtensions
    {
        /// <summary>
        /// Get all framework elemnts from a User Control
        /// </summary>
        /// <param name="obj">User Control to get the Framework Elements</param>
        /// <returns>Framework Elements collection</returns>
        public static List<FrameworkElement> GetAllControls(this UserControl obj)
        {
            return ControlTreeHelper.GetAllControls(obj);
        }

        /// <summary>
        /// Get all the Type controls contained on a Dependency Object
        /// </summary>
        /// <typeparam name="T">Type filter</typeparam>
        /// <param name="obj"></param>
        /// <returns>T controls Collection</returns>
        public static List<T> GetAllControlsByType<T>(this DependencyObject obj)
        {
            return ControlTreeHelper.GetAllControlsByType<T>(obj);
        }

        public static List<DependencyObject> GetAllParentControls(this DependencyObject obj)
        {
            return ControlTreeHelper.GetAllParentControls(obj);
        }

        /// <summary>
        /// Devuelve la lista de controles de usuario de una ventana
        /// </summary>
        /// <param name="window">Ventana de la cual queremos conocer los controles de usuario</param>
        /// <returns></returns>
        public static List<UserControl> GetAllUserControl(this FrameworkElement window)
        {
            return ControlTreeHelper.GetAllUserControl(window);
        }

        /// <summary>
        /// Busca el control único desde esa posición del arbol
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static T GetUniqueControl<T>(this DependencyObject obj)
        {
            return ControlTreeHelper.GetUniqueControl<T>(obj);
        }

        public static T FindNameInVisualTree<T>(this DependencyObject obj, string name)
        {
            return ControlTreeHelper.FindNameInVisualTree<T>(obj, name);
        }

        public static T FindNameInVisualTree<T>(this DependencyObject obj, string name, bool cache)
        {
            return ControlTreeHelper.FindNameInVisualTree<T>(obj, name, cache);
        }

        /// <summary>
        /// Devuelve el contenedor de un UserControl
        /// </summary>
        /// <param name="elemt">elemento del cual queremeos conocer el padre</param>
        /// <returns></returns>
        public static FrameworkElement FindParentUserControl(this FrameworkElement obj)
        {
            return ControlTreeHelper.FindParentUserControl(obj);
        }

        public static T FindUniqueParentalControl<T>(this DependencyObject obj)
        {
            return ControlTreeHelper.FindUniqueParentControl<T>(obj);
        }

        public static T FindVisualChild<T>(this DependencyObject obj) where T : DependencyObject
        {
            return ControlTreeHelper.FindVisualChild<T>(obj);
        }

        public static List<DependencyObject> GetVisualTree(this DependencyObject obj)
        {
            return ControlTreeHelper.GetVisualTree(obj);
        }
    }
}